home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / UNIX / C / C-STYLE / STYLE_DE.C < prev    next >
C/C++ Source or Header  |  1992-11-23  |  854b  |  41 lines

  1. /*******************************************************************
  2.  *  Detab - converrts tabs to appropriate number of spaces
  3.  *  (  transcribed from Kernighan & Plauger's Software tools.
  4.  *******************************************************************
  5.  */
  6.  
  7. #include    <stdio.h>
  8. #define        MAXLINE 132
  9.  
  10. main()
  11. {
  12.     int    c, i, tabs[MAXLINE], col=1;
  13.  
  14.     set_tabs (tabs);
  15.     while (( c = getchar()) != EOF )
  16.         if ( c== '\t' )
  17.             do {putchar (' '); col++;}
  18.             while ( !tab_pos (col, tabs));
  19.         else if ( c== '\n' )
  20.             {putchar( '\n' ); col = 1;}
  21.         else
  22.             {putchar( c ); col++; }
  23. }
  24.  
  25. /* set up tab positions */
  26. set_tabs( tabs )
  27. int    tabs[MAXLINE];
  28. {
  29.     int i;
  30.  
  31.     for ( i = 1; i <= MAXLINE; i++ )
  32.         tabs[i] = (( i % 8) == 1 ? 1: 0);
  33. }
  34.  
  35. /* see if we are at a tab position */
  36. tab_pos( col, tabs )
  37. int     col, tabs[MAXLINE];
  38. {
  39.     return (( col > MAXLINE ) ? 1 : tabs[col] );
  40. }
  41.